<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图书管理系统</title>

<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css">

<script src="../js/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="../js/bootstrap.js" type="text/javascript"></script>

<!-- 使按键失效，用于权限控制  -->
<style type="text/css">
.disable {
	style ="pointer-events: none";
}
</style>

<!-- 导航栏图书检索 -->
<script type="text/javascript">
	function toSearch() {
		window.location.href = "../Book/BookSearch.jsp?book_id=" + document.getElementById("book_id").value;
	}
</script>

<!-- 检查输入格式，并提交图书借阅信息 -->
<script type="text/javascript">
	function send() {
		var type = document.getElementById("type").value;
		var reader_id = document.getElementById("reader_id").value;
		var book_id = document.getElementById("book_ID").value;
		var manager_id = document.getElementById("manager_id").innerHTML;
		var reg_date = document.getElementById("reg_date").innerHTML;
		// 获取当前状态
		if(document.getElementById("status_0").checked) {
			var status = document.getElementById("status_0").value;
		} else {
			var status = document.getElementById("status_1").value;
		}
		
		if(reader_id.length==0) {
			alert("读者ID不能为空！");
		} else if(!reader_id.match("[0-9]+")) {
			alert("读者ID只能为纯数字！");
		} else if(book_id.length==0) {
			alert("图书ID不能为空！");
		} else if(!book_id.match("[0-9]+")) {
			alert("图书ID只能为纯数字！");
		} else {
			$.ajax({
				type:"POST",
				url:"./violationReg.do",
				data:{ type:type,reader_id:reader_id, book_id:book_id, manager_id:manager_id, reg_date:reg_date, status:status },
				dataType:"json",
				success:function(data) {
					if(data.code=="200") {
						// 登记成功
						alert(data.msg);
					} else if(data.code=="401") {
						// 读者ID不存在
						alert(data.msg);
					} else if(data.code=="402") {
						// 图书ID不存在
						alert(data.msg);
					} else if(data.code=="500") {
						// 操作失败
						alert(data.msg);
					} else {
						// 未知错误
						alert("未知错误！");
					}
				},
				errror:function() {
					alert("fail!");
				}
			
		});
		}
	}
</script>

<!-- 重置按钮 -->
<script type="text/javascript">
	function reset() {
		document.getElementById("type").value = "outdate";
		document.getElementById("reader_id").value = "";
		document.getElementById("book_ID").value = "";
		document.getElementById("status_0").checked = true;
	}
</script>

</head>

<body>

<!-- 大背景 -->
	<div class="container" align="center"
		style=" width:auto; height:768px; background-color:#BFEDEA; background-image:url(../img/bg2.png); -moz-background-size:100% 100%; background-size:100% 100%;">

		<!-- 导航栏 -->
		<div style="width:100%; height:auto;">
			<nav class="navbar navbar-default">
				<div class="container-fluid">
					<!-- Brand and toggle get grouped for better mobile display -->
					<div class="navbar-header">

						<a class="navbar-brand" href="../main.jsp">首页</a>
					</div>
					<!-- Collect the nav links, forms, and other content for toggling -->
					<div class="collapse navbar-collapse" id="defaultNavbar1">
						<ul class="nav navbar-nav">
							<!-- 图书管理下拉框 -->
							<li class="dropdown"><a href="#" class="dropdown-toggle"
								data-toggle="dropdown" role="button" aria-expanded="false">图书管理<span
									class="caret"></span></a>
								<ul class="dropdown-menu" role="menu">
									<li><a id="bookManage" href="../Book/BookManage.jsp">管理图书</a></li>
									<li><a id="bookSearch" href="../Book/BookSearch.jsp">图书查询</a></li>
									<li><a id="bookBorrow" href="../Book/BookBorrow.jsp">图书借阅</a></li>
									<li><a id="bookReturn" href="../Book/BookReturn.jsp">图书归还</a></li>
								</ul></li>
								
							<!-- 违规管理下拉框 -->
							<li class="dropdown" id="violation_manage"><a href="#"
								class="dropdown-toggle" data-toggle="dropdown" role="button"
								aria-expanded="false">违规管理<span class="caret"></span></a>
								<ul class="dropdown-menu" role="menu">
									<li><a href="./ViolationManage.jsp">管理违规记录</a></li>
									<li><a href="./ViolationReg.jsp">违规登记</a></li>
								</ul></li>

							<!-- 个人中心下拉框 -->
							<li class="dropdown"><a href="#" class="dropdown-toggle"
								data-toggle="dropdown" role="button" aria-expanded="false">个人中心<span
									class="caret"></span></a>
								<ul class="dropdown-menu" role="menu">
									<li><a href="../User/PersonalImfo.jsp">个人资料</a></li>
									<li id="bookHistory"><a href="../User/BookHistory.jsp">借阅记录</a></li>
									<li id="violationHistory"><a
										href="../User/ViolationHistory.jsp">违规记录</a></li>
									<li><a href="../User/Logout.do">退出登录</a></li>
								</ul></li>

						</ul>
						<!-- 搜索栏 -->
						<div style="float:right;">
							<form class="navbar-form navbar-left" role="search">
								<div class="form-group">
									<input type="text" id="book_id" class="form-control"
										placeholder="输入图书编号">
								</div>
								<button type="button" class="btn btn-default"
									onclick="toSearch()">查询</button>
							</form>
						</div>

				</div>
				<!-- /.navbar-collapse -->
			</div>
			<!-- /.container-fluid --> </nav>
		</div>
        
        <div class="container" align="center" style="width:80%; height:85%; background-color:rgba(255, 255, 255, 0.5);">
       	   <div align="center" style="text-align:center;">
            	<label style="margin:15px 0 0 0; font-family:华文行楷; font-size:35px;">违规登记</label>
                <hr>
            </div>
            <div>
            	<table style=" font-size:18px; margin:10% 2% 2% 2%; padding:1px 9px 1px 9px; border:2px solid #3C9C92; border-collapse:separate; border-spacing:0 10px;">
            	<tr>
                	<td>违规类型：</td>
                	<td>
                    	<select id="type">
                        	<option value="outdate" selected="selected">逾期归还</option>
                            <option value="broken">图书破损</option>
                            <option value="lost">图书遗失</option>
                        </select>
                  	</td>
                </tr>
                <tr>
                	<td>违规读者ID：</td>
                    <td><input type="text" id="reader_id"></td>
                </tr>
                <tr>
                	<td>相关图书ID：</td>
                    <td><input type="text" id="book_ID"></td>
                </tr>
                 <tr>
                	<td>管理员：</td>
                    <td><label id="manager_id"></label></td>
                </tr>
                <tr>
                	<td>登记日期：</td>
                    <td><label id="reg_date"></label></td>
                </tr>
                <tr>
                	<td>当前状态：</td>
                    <td>
                        <input type="radio" name="status" value="false" id="status_0" checked="checked">未处理</input>
                        <input type="radio" name="status" value="true" id="status_1">已处理</input>
                    </td>
                </tr>
                <tr>
                	<td align="center"><button type="submit" id="sumbit" onclick="send()">提交</button></td>
                    <td align="center"><button type="button" onclick="reset()">重置</button></td>
                </tr>
            </table>
            </div>
            </div>
    </div>
</body>

<!-- 权限控制 -->
<script type="text/javascript">
 	var user_type = "<%=session.getAttribute("user_type")%>";
 	if(user_type!=null) {
 		if(user_type=="reader") {
			document.getElementById("bookManage").style['pointer-events'] = 'none';
			document.getElementById("bookBorrow").style['pointer-events'] = 'none';
			document.getElementById("bookReturn").style['pointer-events'] = 'none';
 		} else {
 			document.getElementById("bookHistory").style['pointer-events'] = 'none';
 			document.getElementById("violationHistory").style['pointer-events'] = 'none';
 		}
 	}
</script>

<!-- 渲染当前登录的管理员信息和当前日期 -->
<script type="text/javascript" language="javascript">
	var user = JSON.parse('<%= session.getAttribute("user") %>');
	document.getElementById("manager_id").innerHTML = user.manager_ID;
	var date = new Date();
	document.getElementById("reg_date").innerHTML = date.toLocaleDateString();
</script>

</html>
